﻿using EFMVC.EDMX;
using EFMVC.Interface;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace EFMVC.AchieveInterface
{
    public class SysUserReposity : ISysUserRepositories
    {
        private TPYEntities1 Context;
        public SysUserReposity(TPYEntities1 dbContext)
        {
            this.Context = dbContext;
        }

        public IEnumerable<Sys_User> GetUsers()
        {
            return Context.Sys_User.ToList();
        }
        public Sys_User GetUserByID(Guid userID)
        {
            return Context.Sys_User.Find(userID);
        }
        public void InsertUser(Sys_User user)
        {
            Context.Sys_User.Add(user);
        }
        public void DeleteUser(int userID)
        {
            Sys_User sysUser = Context.Sys_User.Find(userID);
            Context.Sys_User.Remove(sysUser);
        }
        public void UpdateUser(Sys_User user)
        {
            Context.Entry<Sys_User>(user).State = EntityState.Modified;
        }
        public void Save()
        {
            Context.SaveChanges();
        }
        private bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    Context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

    }
}